import pymongo

class MongdbClass():
    def __init__(self, host, database, collect):
        self.clent = pymongo.MongoClient(host)
        self.db = self.clent[database]
        self.col = self.db[collect]

    # 查询所有数据
    def findAll(self):
        return self.col.find()
    
    # 插入多条数据
    def addMany(self, data):
        self.col.insert_many(data)

    # 返回指定条件的数据
    def find(self, condition):
        return self.col.find(condition)
    
    # 删除表中所有数据
    def delAll(self):
        self.col.delete_many({})

if __name__ == "__main__":
    mongo = MongdbClass("182.92.148.234", "Cache", "cache")
    data = []
    for i in mongo.findAll():
        data.append(i)

    backups = MongdbClass("192.168.56.141", "Cache", "cache")
    backups.addMany(data)
    